// run: $exec < input
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

long long p, k, a;

long long quick_pow(long long a, long long b, long long p)
{
	if (b == 0) return 1;
	long long ret = quick_pow(a, b / 2, p);
	ret = (ret * ret) % p;
	if (b & 1) ret = (ret * a) % p;
	return ret;
}

long long primitive_root(long long prime)
{
	std::vector<long long> prime_factor;
	long long phi = prime - 1;
	long long tp = phi;
	for (int i = 2; i * i <= tp; i++) {
		if (!(tp % i)) {
			prime_factor.push_back(i);
			while (!(tp % i)) tp /= i;
		}
	}
	if (tp != 1) prime_factor.push_back(tp);
	for (int i = 2; i < prime; i++) {
		bool is_root = true;
		for (int j = 0; j < (int)prime_factor.size(); j++) {
			int tmp = prime_factor[j];
			if (quick_pow(i, phi/tmp, prime) == 1) {
				is_root = false;
				break;
			}
		}
		if (is_root) return i;
	}
	return -1;
}

namespace hash
{
	int const maxlen = 1299721;
	int hashed[maxlen];
	long long key[maxlen];
	int value[maxlen];
	int timestamp = 1;
	int npos = -1;

	void init() { timestamp++; }

	void insert(long long k, int v)
	{
		int i = k % maxlen;
		for (; hashed[i] == timestamp && key[i] != k; i = (i + 1) % maxlen);
		if (hashed[i] != timestamp) { hashed[i] = timestamp; key[i] = k; value[i] = v; }
	}

	int find(long long k)
	{
		long long i = k % maxlen;
		for (; hashed[i] == timestamp && key[i] != k; i = (i + 1) % maxlen);
		if (hashed[i] != timestamp) return -1;
		return value[i];
	}
};

long long gcd(long long a, long long b)
{
	return !b ? a : gcd(b, a % b);
}

void extended_gcd(long long a, long long b, long long & d, long long & x, long long & y)
{
	if (!b) { d = a; x = 1; y = 0; return; }
	extended_gcd(b, a % b, d, y, x);
	y -= x * (a / b);
}

long long umsole(long long a, long long b, long long p)
{
	long long x, y, b0;
	extended_gcd(a, p, b0, x, y);
	long long m = p / b0;
	return ((x * (b / b0)) % m + m) % m;
}

long long baby_step_gaint_step(long long a, long long b, long long p)
{
	long long m = std::ceil(std::sqrt(((double)p))); // phi(p) = p - 1
	b %= p;
	hash::init();
	long long d = 1;
	for (int i = 0; i < m; i++) {
		hash::insert(d, i);
		d = (d * a) % p;
	}

	// now d = a^m
	long long di = 1; // di = d^i
	for (int i = 0; i < m; i++) {
		long long x = umsole(di, b, p);
		int id = hash::find(x);
		if (id != hash::npos) return i * m + id;
		di = (di * d) % p;
	}
	return -1;

}

int main()
{
	std::cin >> p >> k >> a;
	if (!a) { std::cout << "1\n0\n"; return 0; }
	else if (p == 2) { std::cout << "1\n1\n"; return 0; }
	long long g = primitive_root(p);
	long long x = baby_step_gaint_step(g, a, p);
	if (x == -1) { std::cout << "0\n"; return 0; }
	long long w = umsole(k, x, p - 1);
	long long tgcd = gcd(k, p - 1);
	if (x % tgcd) { std::cout << "0\n"; return 0; }
	long long tk = (p - 1) / tgcd;
//	std::cout << "g = " << g << "  x = " << x << "  w = " << w << '\n';
	std::vector<long long> ans;
	for (; w < p - 1; ) {
		ans.push_back(quick_pow(g, w, p));
		w += tk;
	}
	std::sort(ans.begin(), ans.end());
	std::cout << ans.size() << '\n';
	for (int i = 0; i < (int)ans.size(); i++)
		std::cout << ans[i] << '\n';
}

